if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_InsertIntoSessionBalances]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_InsertIntoSessionBalances] GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_InsertSessionEndingBalances]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_InsertSessionEndingBalances] GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO --Created By : Qaiser Shameer --Dated : 01-Feb-2014 CREATE PROCEDURE sp_InsertIntoSessionBalances @SessionID AS Bigint AS INSERT INTO SessionBalances (SessionID, AccountNo, OpeningBal, DrAmount, CrAmount) SELECT @SessionID, AccountNo, 0 AS Opeing, 0 AS Debit, 0 AS Credit FROM Accounts WHERE (AccountNo NOT IN (SELECT AccountNo FROM SessionBalances WHERE SessionID = @SessionID)) GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO --Created By : Qaiser Shameer --Dated : 01-Feb-2014 CREATE PROCEDURE sp_InsertSessionEndingBalances @SessionID AS Bigint AS INSERT INTO SessionBalances (SessionID, AccountNo, OpeningBal, DrAmount, CrAmount) SELECT @SessionID, AccountNo, 0 AS Opeining, 0 AS Debit, 0 AS Credit FROM Accounts GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO